package cc.lj.internal.api.coupons.api.ticket.fallbackfactory;

import cc.lj.internal.api.coupons.api.ticket.TicketPackageFeignService;
import cc.lj.internal.api.coupons.dto.command.BindTicketPackageAPICommand;
import cc.lj.internal.api.coupons.dto.command.SendPackageAPICommand;
import cc.lj.internal.core.http.HttpResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 券包表fegin回退处理，可以打印出具体回退原因
 * 注意：只有配置文件中开启hystrix (feign.hystrix.enabled=true),该配置才会起作用
 * @author liangxifeng
 * @date 2023-08-24
 */
@Slf4j
@Component
public class TicketPackageFeignServiceFallbackFactory implements FallbackFactory<TicketPackageFeignService> {

    @Override
    public TicketPackageFeignService create(Throwable cause) {
        return new TicketPackageFeignService() {
            @Override
            public HttpResult<Integer> updateBind(BindTicketPackageAPICommand packageCommand) {
                log.error("feign--请求电子券模块: 通过主键修改券包表券关联活动状态失败,入参:"+packageCommand+"原因:" + cause.getMessage());
                return new HttpResult<>(HttpResult.SERVICE_FUSING.getCode(), HttpResult.SERVICE_FUSING.getMessage());
            }

            @Override
            public HttpResult<List<String>> sendPackage(SendPackageAPICommand sendPackageAPICommand) {
                log.error("feign--请求电子券模块: 调用发券包接口失败,入参:"+sendPackageAPICommand+",原因:" + cause.getMessage());
                return new HttpResult<>(HttpResult.SERVICE_FUSING.getCode(), HttpResult.SERVICE_FUSING.getMessage());
            }
        };
    }
}
